package cn.interestingshop.servlet;

import cn.interestingshop.model.entity.Goods;
import cn.interestingshop.service.GoodsService;
import cn.interestingshop.service.GoodsServiceImpl;
import cn.interestingshop.utils.PageUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GoodsServlet",urlPatterns = "/GoodsServlet")
public class GoodsServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String page = request.getParameter("page");//页数

		int currentPage = page==null ? 1: Integer.valueOf(page);

		//操作
		PageUtil<Goods> pageUtil = new PageUtil<>();
		pageUtil.setCurrentPage(currentPage);

		GoodsService service = new GoodsServiceImpl();
		List<Goods> list = service.findGoodByPage(pageUtil.getBeginIndex(), pageUtil.getShowNum());

		pageUtil.setList(list);

		//页面跳转
		request.setAttribute("pageInfo", pageUtil);
		request.getRequestDispatcher("client/goods/BrandList.jsp").forward(request, response);

	}
}
